package com.mbc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mbc.mapper.FansMapper;
import com.mbc.pojo.MbcFans;
import com.mbc.service.FansService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 粉丝表 服务实现类
 * </p>
 *
 * @author suimeng
 * @since 2024-04-08
 */
@Service
public class FansServiceImpl implements FansService {

    @Autowired
    private FansMapper fansMapper;

    /**
     * 通过用户 ID 分页查询粉丝列表
     *
     * @param userId 用户 ID
     * @param page   页
     * @param size   大小
     * @return {@link List}<{@link MbcFans}>
     */
    @Override
    public PageInfo<MbcFans> getAllByUserId(String userId, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<MbcFans> list = fansMapper.getAllByUserId(userId);
        return new PageInfo<>(list);
    }

    /**
     * 分页新增粉丝列表
     *
     * @param userId 用户 ID
     * @return {@link List}<{@link MbcFans}>
     */
    @Override
    public PageInfo<MbcFans> getAddFansList(String userId, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<MbcFans> list = fansMapper.getAddFansList(userId, LocalDateTime.now());
        return new PageInfo<>(list);
    }

    /**
     * 删除粉丝取消关注
     *
     * @param fansId 粉丝 ID
     * @return boolean
     */
    @Override
    public boolean deleteFansUnfollow(String fansId) {
        return fansMapper.deleteFansUnfollow(fansId) > 0;
    }

    /**
     * 新增粉丝
     *
     * @param userId 用户 ID
     * @param fansId 粉丝 ID
     * @return boolean
     */
    @Override
    public boolean insertFans(String userId, String fansId) {
        LocalDateTime now = LocalDateTime.now();
        return fansMapper.insertFans(userId, fansId, now) > 0;
    }

}
